<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>computed</title>
</head>
<body>
  <div id="root"></div>
  
  <script src="https://unpkg.com/vue@next"></script>  
  <script>
    const app = Vue.createApp({
      data() {
        return { 
          message: "Hello Vue",
          count: 10,
          price: 5,
          // total: thsi.count * this.price, // error
        };
      },
      methods: {
        getTotal(){
          console.log('方法计算')
          return this.count * this.price
        }
      },
      // 计算属性 缓存
      computed: {
        total(){
          console.log('计算属性计算')
          return this.count * this.price
        }
      },
      // template: `<div>{{count * price}}</div>`
      // template: `<div>{{getTotal()}}</div>`
      // template: `<div>{{total}}</div>`
      // 计算属性有缓存性能更优； 方法计算每次会重新渲染;
      template: `<div>{{message}} {{getTotal()}} {{total}}</div>`
    });
    const vm = app.mount('#root')
  </script>
</body>
</html>